package com.dao.impl;

import com.dao.CourseDao;
import com.entity.Course;
import com.mapper.CourseMapper;
import com.page.PageInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("courseDao")
public class CourseDaoImpl implements CourseDao {
    @Resource
    public CourseMapper courseMapper;

    @Override
    public List<Course> getAllCourse() throws Exception {
        return courseMapper.selectByExample(null);
    }

    @Override


    public List<Course> getCourseByPage(PageInfo pageInfo)  throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount = (int)courseMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return courseMapper.getCoursesByPage(map);
    }



    public Integer addCourse(Course course)  throws Exception{

        return courseMapper.insertSelective(course);
    }
    public Integer editCourse(Course course)  throws Exception{

        return courseMapper.updateByPrimaryKeySelective(course);
    }


    public String getMaxId(){
        //return courseMapper.getMaxId();
        return null;
    }
}
